package com.xiaozhengkeji.minecraft.plugin.fishplus;


import com.xiaozhengkeji.minecraft.plugin.fishplus.commands.AdministratorCommand;
import com.xiaozhengkeji.minecraft.plugin.fishplus.commands.PlayerCommand;
import com.xiaozhengkeji.minecraft.plugin.fishplus.listener.PlayerEventListener;
import com.xiaozhengkeji.minecraft.plugin.fishplus.utils.MsgUtils;
import com.xiaozhengkeji.minecraft.plugin.fishplus.web.XiaoZhengApiCloud;

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;

/**
 * 全局注册系统
 */

public class RegisterSystem {

    @SuppressWarnings("all")//镇压PlaceholderAPI的弃用警告  从2.11开始PlaceholderAPI用KT全面重写
    public static void registerHook() {
        Plugin placeholderAPI = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
        if (placeholderAPI != null){
            PlaceholderAPI.registerPlaceholderHook("FishPlus", new PlaceholderAPIHook());
        }else {
            MsgUtils.logServer("§4PlaceholderAPI 未加载 [ × ]");
            MsgUtils.logServer("§4Register PlaceholderAPI失败!");
        }
        MsgUtils.logServer("注册HOOK系统完成");


    }
    public static void registerCommands() {
        Bukkit.getPluginCommand("fp").setExecutor(new PlayerCommand());
        Bukkit.getPluginCommand("fpa").setExecutor(new AdministratorCommand());
        MsgUtils.logServer("注册控制器系统完成");

    }
    public static void registerListener() {
        Bukkit.getPluginManager().registerEvents(new PlayerEventListener(), FishPlus.Main);
        MsgUtils.logServer("注册监听系统完成");
    }
    public static void registerDev() {
    }
    public static void infoSystem() {
        MsgUtils.logServer("§a===== §6" + FishPlus.PluginsName + " > 开始启动 §a=====");
        MsgUtils.logServer("> 欢迎使用" + FishPlus.PluginsName + "！");
        MsgUtils.logServer("> 已将您的语言设置为：§f中国 §e(zh_CN)");
        MsgUtils.logServer("> MineCraft版本: §f" + FishPlus.MCVersion);
        if (AuthenticationCompatibility()) {
            MsgUtils.logServer("§a支持本插件! ");
        } else {
            MsgUtils.logServer("§4可能不支持本插件!");
        }
        MsgUtils.logServer("> 该游戏版本已开放使用的功能：");
        MsgUtils.logServer("> 已完成" + FishPlus.PluginsName + "插件全部功能载入！");
        MsgUtils.logServer("> §a作者 §f小正 §a | 版本: §f" + FishPlus.PluginsVersion);
        MsgUtils.logServer("> §a云端记录最新版本: §4" + XiaoZhengApiCloud.getUPVersion());
        MsgUtils.logServer("> 更新内容：");
        String[] upData = XiaoZhengApiCloud.getUPData().split("\n");
        for (int i = 0; i < upData.length; i++) {
            MsgUtils.logServer("> " + upData[i]);
        }
        MsgUtils.logServer("> §4下载地址: §e" + XiaoZhengApiCloud.getDownloadAddress());
        MsgUtils.logServer("> §4定制插件联系QQ: 1419158026 备注(定制)");
        MsgUtils.logServer("§a===== §6" + FishPlus.PluginsName + " > 启动完成 §a=====");
        MsgUtils.logServer("公告:");
        String[] notice = XiaoZhengApiCloud.getNotice().split("\n");
        for (int i = 0; i < notice.length; i++) {
            MsgUtils.logServer("> " + notice[i]);
        }
    }

    static Boolean AuthenticationCompatibility() {
        switch (FishPlus.MCVersion) {
            case "v1_7_R1":
                return true;
            case "v1_7_R2":
                return true;
            case "v1_7_R3":
                return true;
            case "v1_7_R4":
                return true;
            case "v1_8_R1":
                return true;
            case "v1_8_R2":
                return true;
            case "v1_8_R3":
                return true;
            case "v1_9_R1":
                return true;
            case "v1_9_R2":
                return true;
            case "v1_10_R1":
                return true;
            case "v1_11_R1":
                return true;
            case "v1_12_R1":
                return true;
            case "v1_13_R1":
                return true;
            case "v1_14_R1":
                return true;
            case "v1_15_R1":
                return true;
            case "v1_16_R1":
                return true;
            default:
                return false;
        }
    }


}
